<template>
    <div class="user-chat-list-container">
        <el-row type="flex" class="index-box">
            <el-col :span="5" class="height-100-percent">
                <div class="user-list-container">
                    <div class="header">聊天列表</div>
                    <div class="user-list custom-scrollbar none">
                        <div :class="[chatId==item.userInfo.id?'user-item active flex':'user-item flex']"
                             v-for="(item) in chatList"
                             :key="item" @click="handleChat(item.userInfo.id)">
                            <el-badge :value="item.count" :max="9" :hidden="item.count<=0">
                                <div class="avatar flex align-items-center justify-content-center">
                                    <el-icon size="16">
                                        <User/>
                                    </el-icon>
                                </div>
                            </el-badge>
                            <div class="center flex flex-direction-column space-between flex-grow-1">
                                <div class="first flex space-between">
                                    <div class="ip line-one-hidden">{{item.userInfo.username}}</div>
                                    <div class="time">{{item.createdAt}}</div>
                                </div>
                                <div class="text">{{item.content}}</div>
                            </div>
                        </div>
                    </div>
                </div>
            </el-col>
            <el-col :span="19" class="height-100-percent">
                <router-view></router-view>
            </el-col>
        </el-row>
    </div>
</template>

<script setup>
    import {User} from '@element-plus/icons-vue';
    import {computed} from 'vue';
    import {useRouter} from 'vue-router';
    import {useStore} from 'vuex';

    const router = useRouter();
    const store = useStore();
    const chatList = computed(() => store.getters.getChatList);
    const chatId = computed(() => store.getters.getCurrentChatId);
    const handleChat = async (id) => {
        await router.push(`/index/user-chat-detail/${id}`);
    };
</script>

<style lang="less" scoped>
    .user-chat-list-container {
        height: 100%;

        .index-box {
            height: 100%;

            .user-list-container {
                background: #F2F6FC;
                height: 100%;
                border-right: 1px solid #DCDFE6;

                .header {
                    height: 50px;
                    line-height: 50px;
                    border-bottom: 1px solid #C0C4CC;
                    background: #fff;
                }

                .user-list {
                    height: calc(100% - 51px);
                    overflow: auto;
                    padding: 10px 0;
                    -webkit-box-sizing: border-box;
                    -moz-box-sizing: border-box;
                    box-sizing: border-box;

                    .user-item {
                        padding: 10px;
                        cursor: pointer;
                        text-align: left;

                        &.active {
                            background: #DCDFE6;

                            .avatar {
                                border: 1px solid #fff;
                            }
                        }

                        &:hover {
                            background: #DCDFE6;

                            .avatar {
                                border: 1px solid #fff;
                            }
                        }

                        .avatar {
                            width: 38px;
                            height: 38px;
                            border: 1px solid #DCDFE6;
                            -webkit-border-radius: 5px;
                            -moz-border-radius: 5px;
                            border-radius: 5px;
                            position: relative;

                            .point {
                                position: absolute;
                                width: 8px;
                                height: 8px;
                                display: block;
                                background: red;
                                -webkit-border-radius: 50%;
                                -moz-border-radius: 50%;
                                border-radius: 50%;
                                right: -4px;
                                top: -4px;
                            }
                        }

                        .center {
                            margin-left: 10px;
                            font-size: 12px;

                            .first {
                                .ip {
                                    font-weight: 600;
                                    max-width: 120px;
                                }

                                .time {
                                    color: #999;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
</style>